package org.xiaov.framework.component.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.filter.CommonsRequestLoggingFilter;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.xiaov.framework.web.filter.FrameRequestLoggingFilter;
import org.xiaov.framework.web.interceptor.HttpServletHandlerInterceptor;

/**
 * <p>
 * 描述：解web的问题
 * </p>
 *
 * @author xiaovcloud
 * @since 2021/10/7 21:45
 */
@Configuration
public class FrameWebConfig implements WebMvcConfigurer {

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOriginPatterns("*")
                .allowedHeaders("*")
                .allowCredentials(true)
                .allowedMethods("*")
                .maxAge(3600);
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new HttpServletHandlerInterceptor());
    }

    @Bean
    public FrameRequestLoggingFilter frameRequestLoggingFilter() {
        return new FrameRequestLoggingFilter();
    }

//    @Bean
//    public CommonsRequestLoggingFilter requestLoggingFilter() {
//        CommonsRequestLoggingFilter loggingFilter = new CommonsRequestLoggingFilter();
//        loggingFilter.setIncludeClientInfo(true);
//        loggingFilter.setIncludeQueryString(true);
//        loggingFilter.setIncludePayload(true);
//        loggingFilter.setIncludeHeaders(false);
//        return loggingFilter;
//    }
}